<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改报名 ')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-register-edit" th:object="${jsRegister}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">小项：</label>
                <div class="col-sm-8">
                    <select name="itemId" th:field="*{itemId}" class="form-control">
                        <option th:each="item : ${itemList}" th:text="${item.name}" th:value="${item.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">选手：</label>
                <div class="col-sm-8">
                    <select name="playerIds" th:field="*{playerIds}" class="form-control" multiple>
                        <option th:each="player : ${playerList}" th:text="${player.name + '(' + player.idcard + ')'}" th:value="${player.id}"></option>
                    </select>
                </div>
            </div>
            <!--<div class="form-group">-->
                <!--<label class="col-sm-3 control-label">替补：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<select name="replacePlayerIds" th:field="*{replacePlayerIds}" class="form-control" multiple>-->
                        <!--<option th:each="player : ${playerList}" th:text="${player.name + '(' + player.idcard + ')'}" th:value="${player.id}"></option>-->
                    <!--</select>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">作品名称：</label>
                <div class="col-sm-8">
                    <input name="worksName" th:field="*{worksName}" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">照片：</label>
                <div class="col-sm-8">
                    <input type="file" id="file_photo" accept="image/jpg,image/jpeg,image/png"/>
                    <p class="help-block">支持jpg，jpeg，png文件，大小不超过5M</p>
                </div>
            </div>
            <div class="form-group hide">
                <label class="col-sm-3 control-label">音乐：</label>
                <div class="col-sm-8">
                    <input type="file" id="file_music" accept="audio/mp3"/>
                    <p class="help-block">支持mp3文件，大小不超过6M</p>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "js/register";
        $("#form-register-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {

                var formData = new FormData();
                var photoFile = $('#file_photo')[0].files[0];
                if(photoFile && photoFile.size > 6 * 1024 * 1024){
                    $.modal.alertWarning("上传文件大小限制为6M以内");
                    return;
                }
                var musicFile = $('#file_music')[0].files[0];
                if(musicFile && musicFile.size > 6 * 1024 * 1024){
                    $.modal.alertWarning("上传文件大小限制为6M以内");
                    return;
                }
                formData.append("photoFile", photoFile);
                formData.append("musicFile", musicFile);
                var data =  $.common.formToJSON("form-register-edit");
                for(var key in data){
                    formData.append(key, data[key]);
                }

                var config = {
                    url: prefix + "/edit",
                    type: "post",
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: formData,
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍后...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                };
                $.ajax(config);
            }
        }
    </script>
</body>
</html>